Design of Embedded UART Communication Scheme Based on Lua Script Language

introduction

With the gradual increase in the degree of intelligence in substations, there is an increasing demand for the collection of on-site status parameters such as temperature and humidity. For now, in field applications, such devices mostly use UART serial communication methods such as RS232 or RS485 to interact with IED (Intelligent Electronic Device) devices. In general, different devices use different communication data frame formats. A variety of serial data frame formats have caused certain difficulties for the software setting of the IED device. The traditional method is generally specified by the device manufacturer and its supporting peripheral equipment, and the flexibility of the device is not ideal. Aiming at such problems, this paper proposes a solution based on the Lua scripting language, which can effectively improve the adaptability of the IED device to the frame format of various types of serial data packets. This solution hands over the formation and analysis of the specific serial packet protocol to the Lua script for processing, so that the designer can only focus on the design of the relevant interface in the software development of the device, and does not care about the specific serial communication protocol, which is convenient Software stereotypes and improves the flexibility of the device itself in application.

1 Introduction to Lua scripting language

Lua is an open source, free, and lightweight embedded scripting language. The source code is completely ANSI (ISO) C. This makes it very suitable for integration into the current C-based embedded development environment. The key to the interaction between the two is a virtual stack. Through the virtual stack and related interface functions provided by Lua to operate the stack, various types of data can be easily transferred between them.

Compared with other scripting languages ​​(such as Perl, Tcl, Python, etc.), Lua shows sufficient simplicity and very high execution efficiency, combined with its high degree of independence from the platform and sufficient scalability [1], which makes It is gaining more and more attention from everyone. Therefore, the Lua script is preferred for the design in this article.

2 System solution overview

This solution is mainly designed around the communication between the IED device and the peripheral serial device. The system framework is shown in Figure 1.

Figure 1 System framework

When the IED device starts to run, it will create a read and write scheduling task for UART communication. In this task, first start its script engine through the interface function provided by Lua, and create a Lua virtual machine. Then, the C function written by the user can be registered in the Lua virtual machine, and the Lua script file existing in the Flash file system independent of the device C program can be loaded into the virtual machine, thereby establishing an interactive environment of Lua and C. In the system application, the specific data content that needs to be sent to the peripheral device is placed in the Lua script file. When the device C program needs to send data, this part of data is taken out through the cooperation of the communication read-write scheduling program and the virtual machine, and the serial driver is called to send to the peripheral device. When receiving the message sent from the peripheral device to the IED device, the corresponding data is passed to the script program running in the virtual machine for processing, and Lua calls the registered C function to perform related business processing according to the data processing result.

Figure 2 System program flow

The program flow of this system is shown in Figure 2.

Among them, the serial communication chip is implemented by TI's TL16C754B 4-channel programmable UART chip with 64-byte FIFO. Its 4 channels can be independently programmed. Under the operating voltage of 3.3 V, the data transmission rate can be as high as 2 Mbps, which is suitable for applications in a variety of UART communication environments [2]. Based on the application environment of the device, this article uses the RS485 question and answer mechanism and the query method to design the serial communication scheme. In the implementation of the solution, the device will send an inquiry message through the serial chip every certain time, and when the correct response message sent by the peripheral device is inquired, relevant business processing will be performed.

High Voltage Transformer

Ac To Dc Transformer,Ef High Frequency Transformer,Rm 10 Electric Transfomer,110 Volt Transformer

IHUA INDUSTRIES CO.,LTD. , https://www.ihua-coil.com